package net.csdn.business.discuss.api.service.impl;

import cn.hutool.core.util.IdUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import net.csdn.business.discuss.api.mapper.DiscussConfigMapper;
import net.csdn.business.discuss.api.model.dto.NewDiscussConfigDTO;
import net.csdn.business.discuss.api.model.dto.UpdateDiscussConfigDTO;
import net.csdn.business.discuss.api.model.entity.DiscussConfig;
import net.csdn.business.discuss.api.model.query.DiscussConfigQuery;
import net.csdn.business.discuss.api.model.vo.DiscussConfigVO;
import net.csdn.business.discuss.api.service.IDiscussConfigService;
import org.springframework.beans.BeanUtils;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;


/**
 * 讨论配置Service业务层处理
 * 
 * @author zhangyl
 * @date 2023-07-21
 */
@Service
public class DiscussConfigServiceImpl extends ServiceImpl<DiscussConfigMapper, DiscussConfig> implements IDiscussConfigService
{



    /**
     * 根据id查询讨论配置详细信息
     *
     * @param query 查询参数
     * @return 讨论配置
     */
    @Override
    public DiscussConfigVO selectDiscussConfig(DiscussConfigQuery query)
    {
        return baseMapper.selectDiscussConfig(query);
    }

    @Override
    public Boolean isShowDiscuss(DiscussConfigQuery query) {
        Integer result=baseMapper.isShowDiscuss(query);
        if(result==null||result==0){
           return false;
        }else{
            return true;
        }
    }

    /**
     * 修改讨论配置
     *
     * @param params 讨论配置
     * @return 结果
     */
    @Override
    @Transactional(rollbackFor = Exception.class)
    public Integer updateDiscussConfig(UpdateDiscussConfigDTO params)
    {
        DiscussConfig discussConfig=new DiscussConfig();
        BeanUtils.copyProperties(params,discussConfig);
        discussConfig.setCreatedBy(params.getCurrUserId());
        return baseMapper.updateDiscussConfig(discussConfig);
    }

}
